package com.bizmerce.rnd.oms.reporting.web;
import java.awt.Color;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.document.AbstractPdfView;

import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class Korea_Chile extends AbstractPdfView{

	@Override
	protected void buildPdfDocument(Map map, Document document, PdfWriter writer,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		/**FONTS*/
		BaseFont baseFont = BaseFont.createFont("HYGoThic-Medium", "UniKS-UCS2-H", BaseFont.NOT_EMBEDDED);
		BaseFont issuingFont = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);
		Font headerFont = new Font(baseFont, 14, Font.BOLD, Color.black);
		Font normalFont = new Font(baseFont, 8, Font.NORMAL);
		Font boldFont = new Font(Font.HELVETICA, 12, Font.BOLD);
		
		/**TITLE*/
		Paragraph paragraph;
		paragraph = new Paragraph("<양식 3>한-칠레 FTA 원산지증명서",headerFont);
		document.add(paragraph);
		
		paragraph = new Paragraph("KOREA-CHILE FREE TRADE AGREEMENT"+"\n"+"CERTIFICATE OF ORIGIN",boldFont);
		paragraph.setAlignment(Element.ALIGN_CENTER);
		document.add(paragraph);
		
		PdfContentByte cb = writer.getDirectContent();
        cb.beginText();
        cb.setFontAndSize(issuingFont, 9);
        cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Issuing Number : ", 400, 735, 0);
        cb.setFontAndSize(baseFont, 8);
        cb.showText("DFSFS2343");
        cb.endText();
		
        /**TABEL INFORMATION*/
		Table table;
		Cell cell;
		Chunk chunk;
		table = new Table(6);
		int headerwidths[] = { 30, 10, 10, 10, 20, 20};
		table.setWidths(headerwidths);
		table.setPadding(5);
		table.setWidth(100);
		
		/**1 : Exporter*/
		cell = new Cell(new Chunk("1 : Exporter(Name and Address) ",normalFont));
		cell.setColspan(6);
		chunk = new Chunk("1. Heungdeokgu Sindae-dong 221-5, Dong-gu",normalFont);
		cell.add(chunk);
		chunk = new Chunk("\n"+"                                                                        ");
		cell.add(chunk);
		chunk = new Chunk("Tax ID No : ",normalFont);
		cell.add(chunk);
		chunk = new Chunk("1. SDFSD3424234",normalFont);
		cell.add(chunk);
		table.addCell(cell);
		
		/**2 : Producer*/
		cell = new Cell(new Chunk("2 : Producer(Name and Address) ",normalFont));
		chunk = new Chunk("2. 대전광역시 서구 만년동대전광역시 서구 만년동대전광역시 서구 만년동",normalFont);
		cell.add(chunk);
		
		chunk.append("\n"+"                                 ");
		chunk = new Chunk("Tax ID No : ",normalFont);
		cell.add(chunk);
		chunk = new Chunk("2. SDFSD342423434",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		/**3 : Importer*/
		cell = new Cell(new Chunk("3 : Importer(Name and Address) "+"\n",normalFont));
		chunk = new Chunk("대전광역시 서구 만년동",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);

		/**4~8*/
		cell = new Cell(new Paragraph("4. Description of Good(s)",normalFont));
		table.getDefaultCell().setHorizontalAlignment(
				Element.ALIGN_CENTER);
		table.addCell(cell);
		table.addCell(new Paragraph("5. HS No.",normalFont));
		cell = new Cell(new Paragraph("6. Preference Criterion",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		table.addCell(new Paragraph("7. Regional Value Content",normalFont));
		table.addCell(new Paragraph("8. Country of Origin",normalFont));
		
		int firstNum = 0;
		int lastNum = 3;
		
		cell = new Cell();
		for(int i=firstNum;i<=lastNum;i++){
			chunk = new Chunk("1",normalFont);
			cell.add(chunk);
			chunk = new Chunk("\n");
			cell.add(chunk);
		}
		table.addCell(cell);

		cell = new Cell();
		for(int i=firstNum;i<=lastNum;i++){
			chunk = new Chunk("1",normalFont);
			cell.add(chunk);
			chunk = new Chunk("\n");
			cell.add(chunk);
		}
		table.addCell(cell);
		
		cell = new Cell();
		cell.setColspan(2);
		for(int i=firstNum;i<=lastNum;i++){
			chunk = new Chunk("1",normalFont);
			cell.add(chunk);
			chunk = new Chunk("\n");
			cell.add(chunk);
		}
		table.addCell(cell);
		
		cell = new Cell();
		for(int i=firstNum;i<=lastNum;i++){
			chunk = new Chunk("1",normalFont);
			cell.add(chunk);
			chunk = new Chunk("\n");
			cell.add(chunk);
		}
		table.addCell(cell);
		
		cell = new Cell();
		for(int i=firstNum;i<=lastNum;i++){
			chunk = new Chunk("1",normalFont);
			cell.add(chunk);
			chunk = new Chunk("\n");
			cell.add(chunk);
		}
		table.addCell(cell);
		
		/**9. Remarks*/
		cell = new Cell(new Chunk("9. Remarks : ",normalFont));
		chunk = new Chunk("VALUE",normalFont);
		cell.add(chunk);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
		cell.setColspan(6);
		table.addCell(cell);
		
		/**10 : Certification of Origin*/
		cell = new Cell(new Paragraph("10 : Certification of Origin", normalFont));
		cell.setColspan(6);
		chunk = new Chunk("I Certify that : ",normalFont);
		cell.addElement(chunk);
		chunk = new Chunk("\n"+"   |  The information on this document is true and accurate and I assume the responsibility for providing such representations.", normalFont);
		cell.addElement(chunk);
		chunk = new Chunk("\n"+"      I understand that I am liable for any false statements or material omissions made on or in connection with this document", normalFont);
		cell.addElement(chunk);
	
		chunk = new Chunk("\n"+"   |  I agree to maintain and present upon request, documentation necessary to support this certificate, and to inform, in writing,", normalFont);
		cell.addElement(chunk);
		chunk = new Chunk("\n"+"      all persons to whom the certificate was given of any changes that could affect the accuracy or validity of this certificate.", normalFont);
		cell.addElement(chunk);
		
		chunk = new Chunk("\n"+"   |  The goods originated in the territory of the parties, and comply with the origin requirements specified for those goods in", normalFont);
		cell.addElement(chunk);
		chunk = new Chunk("\n"+"      KOREA-CHILE FREE TRADE AGREEMENT. and there has been no further production or any other operation outside the", normalFont);
		cell.addElement(chunk);
		chunk = new Chunk("\n"+"      territories of the Parties in accordance with Article 4.12 of the Agreement.", normalFont);
		cell.addElement(chunk);
		table.addCell(cell);
				
		cell = new Cell(new Chunk("Authorized Signature : ",normalFont));
		chunk = new Chunk("Parties in accordance with Article 4.12 of the Agreement.",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Company Name : ",normalFont));
		chunk = new Chunk("Parties in accordance with Article 4.12 of the Agreement.",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Name(Print or Type) : ",normalFont));
		chunk = new Chunk("Parties in accordance with Article 4.12 of the Agreement.",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Title : ",normalFont));
		chunk = new Chunk("Parties in accordance with Article 4.12 of the Agreement.",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Date(MM/DD/YY) : ",normalFont));
		chunk = new Chunk("Parties in accordance with Article 4.12 of the Agreement.",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Telephone/Fax/Email : ",normalFont));
		chunk = new Chunk("042-123-4567",normalFont);
		cell.add(chunk);
		chunk = new Chunk(" / ",normalFont);
		cell.add(chunk);
		chunk = new Chunk("042-123-4567",normalFont);
		cell.add(chunk);
		chunk = new Chunk(" / ",normalFont);
		cell.add(chunk);
		chunk = new Chunk("042-123-4567",normalFont);
		cell.add(chunk);
		cell.setColspan(3);
		table.addCell(cell);
		
		document.add(table);
	}
}
